/************************************************
The following code produces analyses 
that Figures OA1 and OA2 then 
plot. It must thus be run before the R syntax for this
figure. 
***************************************************/


/***************************
Experiment 2; Figure OA1
***************************/

clear
cd "C:\Users\Joshua\OneDrive\Documents\Work - Finished\BJPS - Comp Explanations\Dataverse"
use exp2_cleaned.dta

***Model
regress therm_post01 ib2.treat_expl##i.copartisan 
		
		margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 
		
		*Within
			*Co-Partisans
				*HC - LC
				test _b[3.treat_expl:1bn._at] = _b[4.treat_expl:1bn._at]
				lincomest _b[3.treat_expl:1bn._at] - _b[4.treat_expl:1bn._at]
				parmest, label saving(NOC_exp2_co_hc, replace)
			
			*Opposing Partisans
				*HC - LC
				regress therm_post01 ib2.treat_expl##i.copartisan 
				margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 
		
				test _b[3.treat_expl:2._at] = _b[4.treat_expl:2._at]
				lincomest _b[3.treat_expl:2._at] - _b[4.treat_expl:2._at]
				parmest, label saving(NOC_exp2_op_hc, replace)
				
		*Between
			regress therm_post01 ib2.treat_expl##i.copartisan 
			margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 
			
			*(Co-Partisan: HC-LC) - (Opposing Partisan: HC-LC)
			mlincom (1-3) - (2-4), stats(all)
				
			matrix rename _mlincom exp2_mat_hc
			
			xsvmat double exp2_mat_hc, rownames(param) rowlabels(varlab) saving(NOC_exp2_mat_hc.dta, replace)
			
			


/***************************
Experiments 3a/3b; Figure OA2
***************************/


/******************************
Experiment 3a 
******************************/

clear
use exp3_cleaned.dta


****Gillibrand
regress gil_post01 ib2.gil_exp##i.gil_partisan

		margins, dydx(3.gil_exp 4.gil_exp) at(gil_partisan=(1 2)) post coeflegend
		
		*Within
			*Co-Partisans: LW - RW
			test _b[3.gil_exp:1bn._at] = _b[4.gil_exp:1bn._at]
			lincomest _b[3.gil_exp:1bn._at] - _b[4.gil_exp:1bn._at]
			parmest, label saving(NOC_exp3_gil_co_hc, replace)

			*Opposing: LW-RW
			 regress gil_post01 ib2.gil_exp##i.gil_partisan 
			 margins, dydx(3.gil_exp 4.gil_exp) at(gil_partisan=(1 2)) post coeflegend
			 
			 test _b[3.gil_exp:2._at] = _b[4.gil_exp:2._at]
			 lincomest _b[3.gil_exp:2._at] - _b[4.gil_exp:2._at]
			 parmest, label saving(NOC_exp3_gil_op_hc, replace)

		*Diff in Diff: (Co-Partisan: LW - RW) - (Opposing Partisan: RW-LW)
			 regress gil_post01 ib2.gil_exp##i.gil_partisan 
			 margins, dydx(3.gil_exp 4.gil_exp) at(gil_partisan=(1 2)) post coeflegend
			 
			 mlincom (1 - 3) - (2-4), stats(all)
			
			matrix rename _mlincom exp3_gil_mat_lwrw
			
			xsvmat double exp3_gil_mat_lwrw, rownames(param) rowlabels(varlab) saving(NOC_exp3_gil_mat_lwrw.dta, replace)
			

/******************************
Experiment 3b
******************************/


****Corker
regress corker_post01 ib2.corker_exp##i.corker_partisan 

	margins, dydx(3.corker_exp 4.corker_exp) at(corker_partisan=(1 2)) post coeflegend
		
		*Within
			*Co-Partisans: LW - RW
			test _b[3.corker_exp:1bn._at] = _b[4.corker_exp:1bn._at]
			lincomest _b[3.corker_exp:1bn._at] - _b[4.corker_exp:1bn._at]
			parmest, label saving(NOC_exp3_corker_co_hc, replace)

			*Opposing: LW-RW
			 regress corker_post01 ib2.corker_exp##i.corker_partisan 
			 margins, dydx(3.corker_exp 4.corker_exp) at(corker_partisan=(1 2)) post coeflegend
			 
			 test _b[3.corker_exp:2._at] = _b[4.corker_exp:2._at]
			 lincomest _b[3.corker_exp:2._at] - _b[4.corker_exp:2._at]
			 parmest, label saving(NOC_exp3_corker_op_hc, replace)

		*Diff in Diff: (Co-Partisan: LW - RW) - (Opposing Partisan: RW-LW)
			 regress corker_post01 ib2.corker_exp##i.corker_partisan 
			 margins, dydx(3.corker_exp 4.corker_exp) at(corker_partisan=(1 2)) post coeflegend
			 
			 mlincom (1 - 3) - (2-4), stats(all)
			
			matrix rename _mlincom exp3_corker_mat_lwrw
			
			xsvmat double exp3_corker_mat_lwrw, rownames(param) rowlabels(varlab) saving(NOC_exp3_corker_mat_lwrw.dta, replace)
			